import java.util.Arrays;
import java.util.Scanner;

public class Test2 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            int n = in.nextInt();
            int k = in.nextInt();
            in.nextLine();
            int[] nums = new int[n];
            for (int i = 0; i < n; i++) {
                nums[i] = in.nextInt();
            }
            Arrays.sort(nums);
            int left = 0;
            int right = 0;
            int minNum = nums[0];
            int ret = 0;
            while (right < n) {
                while (right < n && nums[right]-minNum <= k) {
                    ret = Math.max(ret, right-left+1);
                    right++;
                }
                while (left < right && nums[left] == minNum) {
                    left++;
                }
                if (left < n) {
                    minNum = nums[left];
                }
            }
            System.out.println(ret);
        }
    }
}
